
var urlhead = 'http://www.btcdata.top/api/api_kktoken';

// 整数取有效数字
function changeTwoDecimal(x) {
  if(x == 0){
    return 0;
  }

  var f_x = parseFloat(x);
  if (isNaN(f_x)) {
    return 0;
  }
  var f_x = Math.round(x * 100) / 100;
  var s_x = f_x.toString();
  var pos_decimal = s_x.indexOf('.');
  if (pos_decimal < 0) {
    pos_decimal = s_x.length;
    s_x += '.';
  }
  while (s_x.length <= pos_decimal + 2) {
    s_x += '0';
  }
  return s_x;
}

//  万亿单位汉字转换
function changeBillionToCN(getData) {
  if ((getData.split(".")[0].length) > 8 || (getData.split(".")[0].length) == 8) {
    getData = changeTwoDecimal(getData * 0.00000001) + "亿";
  } else if ((getData.split(".")[0].length) > 4 || (getData.split(".")[0].length) == 4) {
    getData = changeTwoDecimal(getData * 0.0001) + "万";
  } else {
    getData = changeTwoDecimal(getData);
  }
}

function getExchange() {
  $.get(urlhead + '/exchange_lists', function (rangedata) {
    for (let i of rangedata.data.lists) {
      $(".bourse ul").append('<li onclick="setExchangeId(' + i.id + ')">' + i.exchange_name + '</li>')
    }
  });
}

function setExchangeId(id) {
  window.location.href = "/index.html?id=" + id + "&current=1";
}

function toDetail(coin_id, exchange_id) {
  window.location.href = "/html/detail.html?coin_id=" + coin_id + "&exchange_id=" + exchange_id;
}


$(".active").click(function (index) {
  var _this = $(this);
  if (_this.index() == 0) {
    window.location.href = "/index.html?id=&current=" + 1;
  }
})


function GetUrlParam(paraName) {
  var url = document.location.toString();
  var arrObj = url.split("?");

  if (arrObj.length > 1) {
    var arrPara = arrObj[1].split("&");
    var arr;

    for (var i = 0; i < arrPara.length; i++) {
      arr = arrPara[i].split("=");

      if (arr != null && arr[0] == paraName) {
        return arr[1];
      }
    }
    return "";
  }
  else {
    return "";
  }
}